package me.date.a02simpydatedemo2;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class SimpyDemo1 {
    public static void main(String[] args) throws ParseException {
        //extracted();
        //定义一个字符串表示时间
        String str = "2025-11-11 11:11:11";
        //创建对象的格式要跟字符串的格式保持一致f
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date d = sdf.parse(str);
        System.out.println(d.getTime());
    }

    private static void extracted() {
        //空参构造创建对象,默认格式
        SimpleDateFormat sdf = new SimpleDateFormat();
        Date d1 = new Date();
        String str1 = sdf.format(d1);
        System.out.println(str1);
        //带参构造,要指定格式
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss EE");
        Date d2 = new Date(0L);
        String str2 = sdf2.format(d2);
        System.out.println(str2);
    }
}
